package com.ruoyi.web.controller.blacklist;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.member.domain.MemberBlacklist;
import com.ruoyi.member.service.IMemberBlacklistService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 研究所黑名单Controller
 *
 * @author Marissa
 * &#064;date  2023-12-06
 */
@RestController
@RequestMapping("/member/blacklist")
public class MemberBlacklistController extends BaseController {
    @Autowired
    private IMemberBlacklistService memberBlacklistService;

    /**
     * 查询研究所黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberBlacklist memberBlacklist) {
        startPage();
        List<MemberBlacklist> list = memberBlacklistService.selectMemberBlacklistList(memberBlacklist);
        return getDataTable(list);
    }

    /**
     * 导出研究所黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:export')")
    @Log(title = "研究所黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberBlacklist memberBlacklist) {
        List<MemberBlacklist> list = memberBlacklistService.selectMemberBlacklistList(memberBlacklist);
        ExcelUtil<MemberBlacklist> util = new ExcelUtil<>(MemberBlacklist.class);
        util.exportExcel(response, list, "研究所黑名单数据");
    }

    /**
     * 获取研究所黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:query')")
    @GetMapping(value = "/{bId}")
    public AjaxResult getInfo(@PathVariable("bId") Long bId) {
        return success(memberBlacklistService.selectMemberBlacklistByBId(bId));
    }

    /**
     * 新增研究所黑名单
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:add')")
    @Log(title = "研究所黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberBlacklist memberBlacklist) {
        return toAjax(memberBlacklistService.insertMemberBlacklist(memberBlacklist));
    }

    /**
     * 修改研究所黑名单
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:edit')")
    @Log(title = "研究所黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberBlacklist memberBlacklist) {
        return toAjax(memberBlacklistService.updateMemberBlacklist(memberBlacklist));
    }

    /**
     * 删除研究所黑名单
     */
    @PreAuthorize("@ss.hasPermi('member:blacklist:remove')")
    @Log(title = "研究所黑名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bIds}")
    public AjaxResult remove(@PathVariable Long[] bIds) {
        return toAjax(memberBlacklistService.deleteMemberBlacklistByBIds(bIds));
    }
}
